From e747ea7dfd6fd7880083d37a90591367bbe862a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Thu, 17 Dec 2020 19:29:16 +0100 Subject: [PATCH] pixbufutils: Only convert icon size to string once --- gtk/tools/gdkpixbufutils.c | 41 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/gtk/tools/gdkpixbufutils.c b/gtk/tools/gdkpixbufutils.c index 1d6eb4feff..09802f5ef8 100644 --- a/gtk/tools/gdkpixbufutils.c +++ b/gtk/tools/gdkpixbufutils.c @@ -251,9 +251,8 @@ static GdkPixbuf * load_symbolic_svg (const char *escaped_file_data, int width, int height, - double scale, - int icon_width, - int icon_height, + const char *icon_width_str, + const char *icon_height_str, const char *fg_string, const char *success_color_string, const char *warning_color_string, @@ -263,22 +262,13 @@ load_symbolic_svg (const char *escaped_file_data, GInputStream *stream; GdkPixbuf *pixbuf; char *data; - char *svg_width, *svg_height; - - if (width == 0) - width = icon_width * scale; - if (height == 0) - height = icon_height * scale; - - svg_width = g_strdup_printf ("%d", icon_width); - svg_height = g_strdup_printf ("%d", icon_height); data = g_strconcat ("\n" "\n" + " width=\"", icon_width_str, "\"\n" + " height=\"", icon_height_str, "\">\n" " ", NULL); - g_free (svg_width); - g_free (svg_height); stream = g_memory_input_stream_new_from_data (data, -1, g_free); pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream, width, height, TRUE, NULL, error); @@ -446,6 +434,8 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data, { const char *r_string = "rgb(255,0,0)"; const char *g_string = "rgb(0,255,0)"; + char *icon_width_str; + char *icon_height_str; GdkPixbuf *loaded; GdkPixbuf *pixbuf = NULL; int plane; @@ -468,6 +458,13 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data, } escaped_file_data = g_base64_encode ((guchar *) file_data, file_len); + icon_width_str = g_strdup_printf ("%d", icon_width); + icon_height_str = g_strdup_printf ("%d", icon_height); + + if (width == 0) + width = icon_width * scale; + if (height == 0) + height = icon_height * scale; for (plane = 0; plane < 3; plane++) { @@ -483,16 +480,16 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data, * channels, with the color of the fg being implicitly * the "rest", as all color fractions should add up to 1. */ - loaded = load_symbolic_svg (escaped_file_data, width, height, scale, - icon_width, - icon_height, + loaded = load_symbolic_svg (escaped_file_data, width, height, + icon_width_str, + icon_height_str, g_string, plane == 0 ? r_string : g_string, plane == 1 ? r_string : g_string, plane == 2 ? r_string : g_string, error); if (loaded == NULL) - return NULL; + goto out; if (pixbuf == NULL) { @@ -512,6 +509,10 @@ gtk_make_symbolic_pixbuf_from_data (const char *file_data, g_free (escaped_file_data); +out: + g_free (icon_width_str); + g_free (icon_height_str); + return pixbuf; } -- 2.30.2